<?php
// +----------------------------------------------------------------------
// | INPHP
// | Copyright (c) 2023 https://inphp.cc All rights reserved.
// | Licensed ( https://opensource.org/licenses/MIT )
// | Author: 幺月儿(https://gitee.com/lulanyin) Email: inphp@qq.com
// +----------------------------------------------------------------------
// | 权限配置
// +----------------------------------------------------------------------
namespace app\sso\http\api\admin;

use Inphp\Core\Modules;

#[\app\admin\attributes\auth(null, true)] class permission
{
    /**
     * 获取所有模块的权限配置
     * @return array
     */
    public function list(): array
    {
        $modules = Modules::getList();
        //
        $list = [];
        foreach ($modules as $module) {
            $config = $module->getConfig(null, "permission");
            if (is_array($config) && !empty($config)) {
                $list[] = [
                    "name"      => $module->name,
                    "icon"      => $module->config["icon"] ?? null,
                    "value"     => $module->id,
                    "sub"      => $config
                ];
            }
        }
        return $list;
    }
}